package com.example.redisrabbitesintegeation.common.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * @ClassName ResultVO
 * @Description 统一响应视图对象
 * @Author Kx
 * @Date 2025/10/19 19:12
 * @Version 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVO<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T> ResultVO<T> success(T data) {
        ResultVO<T> resultVo = new ResultVO<>();
        resultVo.setCode(HttpStatus.OK.value());
        resultVo.setData(data);
        return resultVo;
    }

    public static <T> ResultVO<T> success() {
        ResultVO<T> resultVo = new ResultVO<>();
        resultVo.setCode(HttpStatus.OK.value());
        return resultVo;
    }

    public static <T> ResultVO<T> error(Integer code, String message) {
        ResultVO<T> resultVo = new ResultVO<>();
        resultVo.setCode(code);
        resultVo.setMessage(message);
        return resultVo;
    }
}